<template>
	<view class="goodslist-container">
		<u-navbar :title="navtitle"> </u-navbar>
		<u-sticky>
			<view style="background: #fff">
				<u-tabs :list="list" @click="tabsTap" :scrollable="false" :current="current"></u-tabs>
			</view>
		</u-sticky>
		<view v-if="current == 0">
			<getdatascrollview :api="getReleaseDiscountPage" :customStyle="scrollviewstyle">
				<template #default="{ list }">
					<view class="goodslist">
						<goodsitem v-for="(item, key) in list" :dicts="dicts" :item="item"
							:levelTypeList="levelTypeList"></goodsitem>
					</view>
				</template>
			</getdatascrollview>
		</view>
		<view v-else-if="current == 1">
			<current1item v-for="(item, key) in current1list" :key="key" :item="item"></current1item>
		</view>
		<view v-else-if="current == 2">
			<current2item v-for="(item, key) in current2list" :key="key" :item="item"></current2item>
		</view>
	</view>
</template>

<script>
	import {
		getReleaseDiscountPage,
		getReleasePage,
		getReleaseList,
	} from "@/api/goods.js";
	import current1item from "./components/current1item.vue";
	import current2item from "./components/current2item.vue";

	import {
		getDicts
	} from "@/api/dictdata";
	import {
		getProductClassAll
	} from "@/api/index.js";
	export default {
		components: {
			current1item,
			current2item
		},
		data() {
			return {
				getReleaseDiscountPage,
				navtitle: "山西饲草收储交易中心",
				query: {},
				list: [{
						name: "特惠区",
					},
					{
						name: "采购区",
					},
					{
						name: "供应区",
					},
				],

				current: 0,
				current1list: [],
				current2list: [],
				dicts: {},
				levelTypeList: [],
				scrollviewstyle: {
					height: `calc(100vh - 88rpx - ${uni.$u.addUnit(
          uni.$u.getPx(uni.$u.props.navbar.height) +
            uni.$u.sys().statusBarHeight,
          "px"
        )})`,
				},
			};
		},
		onLoad(query) {
			this.query = query;
			this.current = query.type || 0;
			this.init();
		},
		mounted() {
			this.getGoodsData();

		},
		methods: {
			async getGoodsData() {
				const res = await getProductClassAll();
				this.levelTypeList = res.data;
				let transactional_mode = await getDicts("transactional_mode");
				transactional_mode = transactional_mode.data;
				let manage_model = await getDicts("manage_model");
				manage_model = manage_model.data;
				this.dicts = {
					transactional_mode,
					manage_model,
				};
			},
			tabsTap(item) {
				this.current = item.index;
				this.init();
			},
			async init() {
				if (this.current == 0) {
					// await getReleaseDiscountPage();
				} else if (this.current == 1) {
					let data = await getReleasePage();
					this.current1list = data.data;
				} else if (this.current == 2) {
					let data = await getReleaseList();
					this.current2list = data.data;
				}
				//
				//
				//  let data= await getReleaseList();
				//   console.log(data);
			},
		},
	};
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.goodslist-container {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}

	.goodslist {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 0 20rpx;
	}
</style>